var primePools = [];
var primes = [];

function getPrimes(limit) {
    var sqrt = Math.floor(Math.sqrt(limit));
    primePools[2] = 0;
    for(var i=2; i<=sqrt; i++) {
        for(var j=i*2; j<=limit; j=j+i) {
            primePools[j] = 1;
        }
    }
}

function isPrime(num) {
    return primePools[num] != 1
}

print('get primes.....');
var t=new Date().getTime();
var plimit = 10000
getPrimes(plimit);
for(var i=2; i<=plimit; i++) {
    if(isPrime(i)) primes.push(i);
}
print('get primes done..... ' + ((new Date().getTime()-t)/1000) + "s");
//print(primes.join("\n"));

//print(getAllNumber(['1','2', '3','4']));

var equalHash = function(i,j) {
    var a= parseInt(j.toString().split("").sort().join(""));
    var b= parseInt(i.toString().split("").sort().join(""));
    //print(a+","+b);
    return a==b
}

for(var i=1001; i<=9998; i++) {
    if(isPrime(i)){
        for(var j=i+1; j<=9999; j++) {
            if(isPrime(j)) {
                if(equalHash(i,j)) {
                    var k=(i+j)/2
                    if(isPrime(k) & equalHash(i,k)) {
                        print(i + "," + k + "," + j);
                    }
                }
            }
        }
    }
}


